package com.ziyun.erp.web.modules.message.controller;

import com.ziyun.erp.modules.message.entity.MessageUserEntity;
import com.ziyun.erp.modules.message.service.MessageUserService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 提示消息人员关系表
 *
 * @author zh
 * @email 296588519@qq.com
 * @date 2018-08-13 14:22:52
 */
@RestController
@RequestMapping("message/messageuser")
public class MessageUserController {
    @Autowired
    private MessageUserService messageUserService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("message:messageuser:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = messageUserService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("message:messageuser:info")
    public R info(@PathVariable("id") Integer id){
        MessageUserEntity messageUser = messageUserService.selectById(id);

        return R.ok().put("messageUser", messageUser);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("message:messageuser:save")
    public R save(@RequestBody MessageUserEntity messageUser){
        messageUserService.insert(messageUser);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("message:messageuser:update")
    public R update(@RequestBody MessageUserEntity messageUser){
        ValidatorUtils.validateEntity(messageUser);
        messageUserService.updateAllColumnById(messageUser);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("message:messageuser:delete")
    public R delete(@RequestBody Integer[] ids){
        messageUserService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
